const user = {
  state: {
    userInfo: null, // 用户信息
    userSig: "",
  },
  mutations: {
    updateUserItem(state, { field, value }) {
      state[field] = value
    }
  },
  actions: {
    getUser({ store, commit }) {
      return {}
    },
    // 登录
    login({ state, commit }) {
      if (!state.userInfo.keyID || !state.userSig) {
        return Promise.reject(new Error('未获取到短链码'))
      }
      return tim.login({ userID: state.userInfo.keyID, userSig: state.userSig }).then(res => {
        commit('startComputeCurrent')
        console.log('登录返回的数据：', res)
      })
    },
    logout(context) {
      context.commit('stopComputeCurrent')
    }
  }
}

export default user
